from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-28 14:10:36.429663
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 28, Mar, 2021
Time: 14:10:41
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.1453
Nobs: 244.000 HQIC: -47.9157
Log likelihood: 2883.11 FPE: 9.22637e-22
AIC: -48.4352 Det(Omega_mle): 6.42740e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.450370 0.128948 3.493 0.000
L1.Burgenland 0.070079 0.063625 1.101 0.271
L1.Kärnten -0.218183 0.054804 -3.981 0.000
L1.Niederösterreich 0.079860 0.141520 0.564 0.573
L1.Oberösterreich 0.220616 0.131683 1.675 0.094
L1.Salzburg 0.262734 0.071341 3.683 0.000
L1.Steiermark 0.140866 0.092893 1.516 0.129
L1.Tirol 0.115219 0.062525 1.843 0.065
L1.Vorarlberg -0.029509 0.057746 -0.511 0.609
L1.Wien -0.078162 0.118527 -0.659 0.510
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.478737 0.153936 3.110 0.002
L1.Burgenland 0.005602 0.075955 0.074 0.941
L1.Kärnten 0.338337 0.065424 5.171 0.000
L1.Niederösterreich 0.108510 0.168945 0.642 0.521
L1.Oberösterreich -0.082449 0.157202 -0.524 0.600
L1.Salzburg 0.211261 0.085166 2.481 0.013
L1.Steiermark 0.127506 0.110894 1.150 0.250
L1.Tirol 0.136285 0.074642 1.826 0.068
L1.Vorarlberg 0.156213 0.068937 2.266 0.023
L1.Wien -0.467245 0.141496 -3.302 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.301946 0.062724 4.814 0.000
L1.Burgenland 0.094754 0.030949 3.062 0.002
L1.Kärnten -0.014833 0.026658 -0.556 0.578
L1.Niederösterreich 0.050335 0.068839 0.731 0.465
L1.Oberösterreich 0.287943 0.064054 4.495 0.000
L1.Salzburg 0.015417 0.034702 0.444 0.657
L1.Steiermark 0.022449 0.045185 0.497 0.619
L1.Tirol 0.067280 0.030414 2.212 0.027
L1.Vorarlberg 0.083255 0.028089 2.964 0.003
L1.Wien 0.097188 0.057655 1.686 0.092
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211801 0.064230 3.298 0.001
L1.Burgenland 0.020338 0.031692 0.642 0.521
L1.Kärnten 0.008379 0.027298 0.307 0.759
L1.Niederösterreich 0.046336 0.070493 0.657 0.511
L1.Oberösterreich 0.400565 0.065593 6.107 0.000
L1.Salzburg 0.081517 0.035536 2.294 0.022
L1.Steiermark 0.139431 0.046271 3.013 0.003
L1.Tirol 0.047884 0.031144 1.537 0.124
L1.Vorarlberg 0.082311 0.028764 2.862 0.004
L1.Wien -0.038412 0.059040 -0.651 0.515
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.516172 0.125841 4.102 0.000
L1.Burgenland 0.081132 0.062092 1.307 0.191
L1.Kärnten 0.012031 0.053483 0.225 0.822
L1.Niederösterreich -0.027305 0.138110 -0.198 0.843
L1.Oberösterreich 0.130097 0.128510 1.012 0.311
L1.Salzburg 0.053404 0.069622 0.767 0.443
L1.Steiermark 0.100837 0.090654 1.112 0.266
L1.Tirol 0.212224 0.061019 3.478 0.001
L1.Vorarlberg 0.029085 0.056355 0.516 0.606
L1.Wien -0.098281 0.115671 -0.850 0.396
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.193835 0.096613 2.006 0.045
L1.Burgenland -0.021411 0.047670 -0.449 0.653
L1.Kärnten -0.016979 0.041061 -0.414 0.679
L1.Niederösterreich -0.022381 0.106032 -0.211 0.833
L1.Oberösterreich 0.422708 0.098662 4.284 0.000
L1.Salzburg 0.008251 0.053451 0.154 0.877
L1.Steiermark -0.004372 0.069599 -0.063 0.950
L1.Tirol 0.159556 0.046846 3.406 0.001
L1.Vorarlberg 0.055297 0.043266 1.278 0.201
L1.Wien 0.231000 0.088805 2.601 0.009
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.246590 0.121587 2.028 0.043
L1.Burgenland 0.018432 0.059993 0.307 0.759
L1.Kärnten -0.062824 0.051676 -1.216 0.224
L1.Niederösterreich -0.058299 0.133442 -0.437 0.662
L1.Oberösterreich 0.012617 0.124167 0.102 0.919
L1.Salzburg 0.076266 0.067269 1.134 0.257
L1.Steiermark 0.340252 0.087590 3.885 0.000
L1.Tirol 0.455823 0.058956 7.732 0.000
L1.Vorarlberg 0.149031 0.054450 2.737 0.006
L1.Wien -0.172597 0.111762 -1.544 0.123
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126537 0.143197 0.884 0.377
L1.Burgenland 0.050575 0.070656 0.716 0.474
L1.Kärnten -0.068954 0.060860 -1.133 0.257
L1.Niederösterreich 0.196971 0.157158 1.253 0.210
L1.Oberösterreich -0.015235 0.146234 -0.104 0.917
L1.Salzburg 0.205278 0.079224 2.591 0.010
L1.Steiermark 0.128342 0.103157 1.244 0.213
L1.Tirol 0.052256 0.069434 0.753 0.452
L1.Vorarlberg 0.099992 0.064128 1.559 0.119
L1.Wien 0.227732 0.131625 1.730 0.084
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.587575 0.077757 7.557 0.000
L1.Burgenland -0.040470 0.038367 -1.055 0.292
L1.Kärnten -0.025903 0.033047 -0.784 0.433
L1.Niederösterreich 0.011775 0.085338 0.138 0.890
L1.Oberösterreich 0.330380 0.079406 4.161 0.000
L1.Salzburg 0.018016 0.043019 0.419 0.675
L1.Steiermark -0.028597 0.056015 -0.511 0.610
L1.Tirol 0.087069 0.037703 2.309 0.021
L1.Vorarlberg 0.112237 0.034822 3.223 0.001
L1.Wien -0.043643 0.071473 -0.611 0.541
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137679 0.033651 0.159957 0.213788 0.054875 0.077203 -0.002129 0.152535
Kärnten 0.137679 1.000000 0.015481 0.204014 0.175665 -0.069854 0.157577 0.021377 0.304500
Niederösterreich 0.033651 0.015481 1.000000 0.247864 0.067229 0.292460 0.138286 0.029519 0.301053
Oberösterreich 0.159957 0.204014 0.247864 1.000000 0.300715 0.276435 0.087317 0.057859 0.133526
Salzburg 0.213788 0.175665 0.067229 0.300715 1.000000 0.155960 0.047230 0.090023 -0.001675
Steiermark 0.054875 -0.069854 0.292460 0.276435 0.155960 1.000000 0.110176 0.094213 -0.135002
Tirol 0.077203 0.157577 0.138286 0.087317 0.047230 0.110176 1.000000 0.164519 0.145072
Vorarlberg -0.002129 0.021377 0.029519 0.057859 0.090023 0.094213 0.164519 1.000000 0.003091
Wien 0.152535 0.304500 0.301053 0.133526 -0.001675 -0.135002 0.145072 0.003091 1.000000